﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace SHARED
{
    public class MasterElementList : List<MasterElement>
    {
        public MasterElement parent;

        public MasterElementList(MasterElement parent)
        {
            this.parent = parent;
        }

        public void Add(MasterElement masterElement)
        {
            if (masterElement.Parent == null)
            {
                masterElement.Parent = parent;
            }
            if (base.Contains(masterElement.Parent))
            {
                masterElement.Parent = base[base.IndexOf(masterElement.Parent)];
                //base[base.IndexOf(masterElement.Parent)].AddChild(masterElement);
            }
            if (!base.Contains(masterElement))
            {
                base.Add(masterElement);
            }
            else
            {
                base[base.IndexOf(masterElement)].occurences++;
            }
            
        }

        public MasterElement findMasterElement(MasterElement me)
        {
            if (base.IndexOf(me) != -1)
            {
                return base[base.IndexOf(me)];
            }
            return null;
        }

    }
}
